package com.zsw.controller;

import com.zsw.entity.Commodity;
import com.zsw.service.CommodityService;
import feign.FeignException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhangsw
 */
@RestController
@Api(tags = "商品服务")
public class CommodityController {
    @Resource
    private CommodityService commodityService;

    @ApiOperation("通过id获取商品")
    @GetMapping("/commodity/get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品id")
    })
    public Commodity getCommodityById(@RequestParam("id") Integer id) throws FeignException {
        return commodityService.getCommodityById(id);
    }

    @ApiOperation("添加商品")
    @PostMapping("/commodity/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodity",value = "商品")
    })
    public Boolean addCommodityById(Commodity commodity) throws FeignException{
        return commodityService.addCommodity(commodity)>0;
    }
}
